﻿using System;
using System.Linq;
using System.ComponentModel.Composition;
using System.Collections.Generic;

namespace GlobalOfficeTools.Framework.ChildWindowService
{
    [PartCreationPolicy(CreationPolicy.Shared)]
    [Export(typeof(IChildWindowService))]
    public class ChildWindowService : IChildWindowService
    {
        #region Public Properties 
        [ImportMany("ChildWindow", AllowRecomposition = true)]
        public IEnumerable<Lazy<object, IChildWindowMetadata>> _childWindowLazy { get; set; }
        #endregion

        #region Constuctor 
        public ChildWindowService() { }
        #endregion

        #region IChildWindowService Implementation 
        public void ShowDialog(string contractName) 
        {
            var oChildWindow = _childWindowLazy.Single(x => x.Metadata.Name.Equals(contractName)).Value;
            ((IModalWindow)oChildWindow).Show();
        }
        #endregion
    }
}
